<template>
  <div>
    <el-dropdown>
      <span class="el-dropdown-link">
        <span>欢迎您，{{ userName ? userName : '超级管理员' }}</span>
        <i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <el-dropdown-menu slot="dropdown" >
        <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  computed: {
    userName () {
      return this.$store.state.users.userInfo.nns_name
    }
  },
  methods: {
    // 退出
    logout () {
      this.$confirm('是否退出登录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$store.dispatch('Logout').then(() => {
          window.location.href = '/'
        })
        this.$modal.success(this, '退出成功')
      }).catch(() => {
        this.$modal.info(this, '操作已取消')
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .el-dropdown-link {
    font-size: 16px;
    cursor: pointer;
    border: none;
    i {
      transition: all 0.5s ease-in-out;
      &:hover {
        transform: rotate(180deg);
      }
    }
  }
</style>
